xen: arm: avoid truncation in mfn to paddr conversions
authorIan Campbell <ian.campbell@citrix.com>
Mon, 2 Dec 2013 11:11:40 +0000 (11:11 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 2 Dec 2013 13:56:24 +0000 (13:56 +0000)
commit9ca423b1fb164a30f40bfacc6c03106fbe1945b1
treeca5cf7aa0b059aa83bb7c1b1cb8824ab014184d2
parentb49827a385716ef94d466aa34640c56824800b90
xen: arm: avoid truncation in mfn to paddr conversions

Although MFNs are 64-bit in the hypercall ABI they are most often unsigned
long internally, and therefore be 32-bit on arm32. Physical addresses are
always 64-bit via paddr_t.

This means that the common "mfn << PAGE_SHIFT" pattern risks losing some of
the top bits of the address is high enough. This need not imply a high amount
of RAM, just a sparse physical address map.

The correct form is ((paddr_t)mfn)<<PAGE_SHIFT and we have the pfn_to_paddr
macro which implements this. Grep for PAGE_SHIFT and << and switch to the
macro everywhere we can in the arch specific code. Note that page.h is
included by mm.h which defines the macro and so remains with the open coded
cast. I have inspected the common code matching this pattern and it uses the
correct casts where necessary (x86 also has pfn_to_paddr, so as a further
cleanup we could fix the common code too, but I haven't done that here).

I observed this as failure to boot a guest on midway, due to trying to map a
foreign page which belonged to no guest. I think this likely explains the
crashes which Julien has seen too.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
xen/arch/arm/domain_build.c
xen/arch/arm/mm.c
xen/arch/arm/p2m.c
xen/arch/arm/setup.c
xen/include/asm-arm/mm.h